import axios from 'axios'

//import { refresh } from '../api/userLogin'


import {reactive} from "vue";
const baseUrl=reactive({
    Base_store_URL:'/api',
    Base_api2_URL:'/faceapi'
})


let service = axios.create({
    baseURL: baseUrl.Base_store_URL,
    timeout: 5000
})


// 请求拦截: 每一次发请求都会做的事情
service.interceptors.request.use(
    (config:any) => {
        if (config.url=="/face/query"){
            config.baseURL=baseUrl.Base_api2_URL
        }else {
            config.baseURL=baseUrl.Base_store_URL
        }
        // const token = getToken() as string
        // if (token) {
        //     config.headers!['token'] = token
        // }
        return config
    },
    (error:any) => {
        return Promise.reject(error)
    }
)


//响应拦截
service.interceptors.response.use((response:any) => {
    return response.data
}, (err:any) => {
    const res = err
    if (res.response.status === 404) {

    } else if (res.response.status === 500) {


    }
    return Promise.reject(err)
})

export default service
